package iit.projects.etaxi.model.service;

import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import iit.projects.etaxi.model.dao.CityDao;
import iit.projects.etaxi.model.dto.CitySCDO;
import iit.projects.etaxi.model.entity.City;
import iit.projects.etaxi.model.exception.CityNotFoundException;
import iit.projects.etaxi.model.exception.DuplicateCityException;

@Transactional(readOnly = true)
public class CityServiceImpl implements CityService {

	private CityDao cityDao;
	
	@Override
	@Transactional( readOnly=false, propagation=Propagation.REQUIRES_NEW, rollbackFor={DuplicateCityException.class})
	public City saveCity(City city) throws DuplicateCityException {
		return cityDao.addCity(city);
	}
	
	@Override
	public List<City> findCities(CitySCDO citySCDO){
		return cityDao.findCities(citySCDO);
	}
	
	@Override
	@Transactional( readOnly=false, propagation=Propagation.REQUIRES_NEW)
	public City updateCity(City city){
		return cityDao.updateCity(city);
	}
	
	@Override
	@Transactional( readOnly=false, propagation=Propagation.REQUIRES_NEW)
	public void deleteCity(City city){
		cityDao.deleteCity(city);
	}
	@Override
	public City findByPrimaryKey(String code) throws CityNotFoundException{
		return cityDao.findByPrimaryKey(code);
	}
	
	public void setCityDao(CityDao cityDao) {
		this.cityDao = cityDao;
	}

}
